#include "PointSignature.h"


#define UMBILICAL_THRESHOLD		0.75
#define PARABOLIC_TOLERANCE		0.15

PointSignature::PointSignature( int id, Monge_form monge )
{
	idx = id;

	p = monge.origin();
	n = monge.Normaldirection();
	d1 = monge.maximal_principal_direction();
	d2 = monge.minimal_principal_direction();

	// It seems the curvatures returned by monge_via_jet_fitting have an opposite sign 
	k1 = -monge.principal_curvatures(0);
	k2 = -monge.principal_curvatures(1);
	K = k1 * k2;

	// Sort k1 and k2 by absolute value
	if (abs(k1) < abs(k2))
	{
		std::swap(d1, d2);
		std::swap(k1, k2);
	}
}

// A point x on the surface is called
// - elliptic. if K > 0
// - parabolic, if K = 0
// - hyperbolic, if K < 0
// - umbilical, if k1 = k2
void PointSignature::determinType()
{
	if (std::max(abs(k1), abs(k2)) < PARABOLIC_TOLERANCE)
	{
		type = UMBILICAL;
	}
	else if (std::min(abs(k1), abs(k2)) < PARABOLIC_TOLERANCE) 
	{
		type = PARABOLIC;
	}
	else 
	{
		if (K > 0)	type = ELLIPTIC;
		else		type = HYPERBOLIC;

		if (abs(k2 / k1) > UMBILICAL_THRESHOLD)
			type = UMBILICAL;
	}
}

Vec2d PointSignature::curvaturesAsVec2d()
{
	return Vec2d(k1, k2);
}
